package org.guderin.bookmarkus.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.guderin.bookmarkus.dao.BookmarkDao;

public class AddBookmark extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7292538619476114781L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String jsp = "/WEB-INF/pages/addBookmarkForm.jsp";
		 
		RequestDispatcher rd = getServletContext().getRequestDispatcher(jsp);
		rd.forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String url = req.getParameter("url");
		String name = req.getParameter("name");
		String description = req.getParameter("description");
		String author = req.getParameter("author");
		
		System.out.println("url = " + url);
		System.out.println("name = " + name);
		
		BookmarkDao bookmarkDao = new BookmarkDao();
		bookmarkDao.add(author, url, description, name);
		
		String jsp = "/WEB-INF/pages/addBookmarkForm.jsp";
		RequestDispatcher rd = getServletContext().getRequestDispatcher(jsp);
		rd.forward(req, resp);		
		
	}
	

}
